package com.wxy.demo.util;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class ApiResponse<T> {
    private String code;
    private String msg;
    private T data;

    public static <T> ApiResponse<T> ok() {
        return new ApiResponse<>("0000", "success", null);
    }

    public static <T> ApiResponse<T> ok(String msg, T data) {
        return new ApiResponse<>("0000", msg, data);
    }

    public static <T> ApiResponse<T> ok(T data) {
        return new ApiResponse<>("0000", "success", data);
    }

    public static <T> ApiResponse<T> fail() {
        return new ApiResponse<>("0001", "error", null);
    }

    public static <T> ApiResponse<T> fail(String msg) {
        return new ApiResponse<>("0001", msg, null);
    }

    public static <T> ApiResponse<T> fail(String msg, T data) {
        return new ApiResponse<>("0001", msg, data);
    }

    public static <T> ApiResponse<T> fail(String code, String msg, T data) {
        return new ApiResponse<>(code, msg, data);
    }

    public static <T> ApiResponse<T> fail(String code, String msg) {
        return new ApiResponse<>(code, msg, null);
    }
}
